package org.swfer.UIC 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	/**
	 * 按钮分组容器
	 * Abstract
	 * @author swfer
	 */
	public class ButtonGroup extends Component 
	{
		
		protected var buttons:Array;
		protected var buttonViews:Array;
		protected var _array:Array;
		protected var itemDef:Class;
		
		public function ButtonGroup(view:MovieClip) 
		{
			super(view);
			
		}
		
		override public function dispose():void
		{
			if (disposed) return;
			super.dispose();
			
			for each (var item:Component in buttons) 
			{
				item.dispose();
			}
			
			_array = null;
			buttons = null;
		}
		
		override protected function init():void
		{
			buttons = [];
			buttonViews = [];
			
			for (var i:int = 0; i < int.MAX_VALUE; i++) 
			{
				var item:MovieClip = view.getChildByName('item' + i) as MovieClip;
				if (item == null) break;
				var btn:Component = new itemDef(item);
				btn.injectMethod = injectMx;
				buttons.push(btn);
				buttonViews.push(item);
				item.buttonMode = true;
			}
		}
		
		override protected function addEvt():void
		{
			for each (var item:MovieClip in buttonViews) 
			{
				item.addEventListener(MouseEvent.CLICK,onItemClick);
			}
		}
		
		override protected function removeEvt():void
		{
			for each (var item:MovieClip in buttonViews) 
			{
				item.removeEventListener(MouseEvent.CLICK,onItemClick);
			}
		}
		
		protected function onItemClick(e:MouseEvent):void 
		{
			trace('not implemented');
		}
		
		public function get array():Array { return _array;}
		public function set array(value:Array):void 
		{
			_array = value;
			for (var i:int = 0; i < _array.length; i++) 
			{
				buttons[i].injectData = _array[i];
			}
		}
		
	}

}